<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li
      v-for="item in showList"
      :key="item.id"
      :class="{ completed: item.isDone }"
    >
      <div class="view">
        <input
          @click="checkBox(item.id)"
          v-model="item.isDone"
          class="toggle"
          type="checkbox"
        />
        <label>{{ item.name }}</label>
        <button @click="del(item.id)" class="destroy"></button>
      </div>
    </li>
  </ul>
</template>

<script>
// 导入
import { mapState, mapMutations, mapGetters } from 'vuex'

export default {
  computed: {
    // 映射数据
    ...mapState(['list']),
    ...mapGetters(['showList'])
  },
  methods: {
    // 导入 方法
    ...mapMutations(['delTask', 'checkedBox']),

    //  删除单项
    del (id) {
      this.delTask(id)
    },
    // 单选控制全选
    checkBox (id) {
      this.checkedBox(id)
    }
  }
}
</script>
